import React, { useCallback, useState } from 'react'
import  Child5 from "../components/Child5";

export default function UseCallBack() {

    const [num, setNum] = useState(10);
    const [n, setn] = useState(99)

    let total = useCallback(
        () => {
            console.log("11111");
            // return 2 * num;
            setNum(num+1);
        },
        [num],
    )
    return (
        <div>UseCallBack
            <h3>num为{num}</h3>
            <h3>n为{n}</h3>
            {/* <h3>计算结果{total()}</h3> */}
            <button onClick={() => {
               total();

            }}>计算num</button>
            <button onClick={() => {
                setn(n + 1);
            }}>计算n</button>

            <Child5 num={num}></Child5>
        </div>
    )
}
